#ifndef _SRC_NET_POLLER_EPOLL_POLLER_H_
#define _SRC_NET_POLLER_EPOLL_POLLER_H_

#include "src/net/poller.h"

struct epoll_event;

namespace fio66::net {
///
/// IO Multiplexing with epoll(4).
///
class EPollPoller : public Poller {
 public:
  EPollPoller(EventLoop* loop);
  ~EPollPoller() override;

  Timestamp Poll(int timeoutMs, ChannelList* activeChannels) override;
  void UpdateChannel(Channel* channel) override;
  void RemoveChannel(Channel* channel) override;

 private:
  static const int kInitEventListSize = 16;

  static const char* OperationToString(int op);

  void FillActiveChannels(int numEvents, ChannelList* activeChannels) const;
  void Update(int operation, Channel* channel);

  typedef std::vector<struct epoll_event> EventList;

  int epoll_fd_;
  EventList events_;
};

}  // namespace fio66::net

#endif  // _SRC_NET_POLLER_EPOLL_POLLER_H_
